Skip to content

Override ProcessOutputLine.ToString() to return Content#128359

Merged
adamsitnik merged 4 commits into
mainfrom
copilot/override-tostring-return-content
May 19, 2026
Merged

Override ProcessOutputLine.ToString() to return Content#128359
adamsitnik merged 4 commits into
mainfrom
copilot/override-tostring-return-content

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

Description

ProcessOutputLine.ToString() returned the default type name ("System.Diagnostics.ProcessOutputLine"), making Console.WriteLine(line) useless without explicitly accessing .Content.

This adds a ToString() override returning Content ?? string.Empty, following the same pattern used by StringSegment and StringValues in Microsoft.Extensions.Primitives. The ?? string.Empty guard ensures the method never returns null for a default-initialized struct, which aligns with the .NET docs requirement that ToString() should not return null or string.Empty as a meaningful value in normal usage:

await foreach (var line in process!.ReadAllLinesAsync())
{
    Console.WriteLine(line); // now prints actual output instead of type name
}

Changes

  • ProcessOutputLine.cs: Added public override string ToString() => Content ?? string.Empty;
  • ref/System.Diagnostics.Process.cs: Added ToString() to the reference assembly
  • ProcessStreamingTests.cs: Added unit tests for ToString() behavior; default struct case asserts string.Empty

Copilot AI requested review from Copilot and removed request for Copilot May 19, 2026 08:27
Copilot AI linked an issue May 19, 2026 that may be closed by this pull request
Copilot AI requested review from Copilot and removed request for Copilot May 19, 2026 08:52
Copilot AI changed the title [WIP] Fix ProcessOutputLine.ToString to return Content Override ProcessOutputLine.ToString() to return Content May 19, 2026
Copilot AI requested a review from adamsitnik May 19, 2026 08:53
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address my feedback

Comment thread src/libraries/System.Diagnostics.Process/tests/ProcessStreamingTests.cs Outdated
Copilot AI requested review from Copilot and removed request for Copilot May 19, 2026 13:14
@adamsitnik adamsitnik marked this pull request as ready for review May 19, 2026 13:14
Copilot AI review requested due to automatic review settings May 19, 2026 13:14
Comment thread src/libraries/System.Diagnostics.Process/tests/ProcessStreamingTests.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes System.Diagnostics.ProcessOutputLine to override ToString() so it returns the line’s text content, aligning default formatting (e.g., Console.WriteLine(line)) with typical expectations for “line” types.

Changes:

  • Override ProcessOutputLine.ToString() to return Content.
  • Update the System.Diagnostics.Process reference assembly to include the ToString() override.
  • Add unit tests validating ToString() behavior for populated and default struct cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.Diagnostics.Process/tests/ProcessStreamingTests.cs Adds tests covering ProcessOutputLine.ToString() for common inputs and default struct behavior.
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessOutputLine.cs Implements ToString() override returning Content.
src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs Adds the ToString() override to the public API contract in the reference assembly.

Copilot AI requested a review from adamsitnik May 19, 2026 13:26
Copy link
Copy Markdown
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable

@adamsitnik adamsitnik enabled auto-merge (squash) May 19, 2026 14:36
@adamsitnik adamsitnik added this to the 11.0.0 milestone May 19, 2026
@adamsitnik adamsitnik merged commit c6a8e4c into main May 19, 2026
94 checks passed
@adamsitnik adamsitnik deleted the copilot/override-tostring-return-content branch May 19, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

suggestion: make ProcessOutputLine.ToString return Content

4 participants